home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / AEmotionPathTemplate.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  15.3 KB  |  518 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //    Alias|Wavefront Script File
  19. //
  20. //    Creation Date:    May 29, 1997
  21. //    Author:            ajp
  22. //
  23. //    Procedure Name:
  24. //    AEmotionPathTemplate
  25. //
  26. //    Description Name;
  27. //    Creates the attribute editor controls for the motionPath node
  28. //
  29. //    Input Value:
  30. //    nodeName
  31. //
  32. //    Output Value:
  33. //    None
  34. //
  35.  
  36. // Global strings used to keep track of custom UI in
  37. // tear-off copies of the motionPath attribute editor.
  38. // These are cleared in resetAE.mel which gets called on
  39. // all file operations.
  40. //
  41. global string $gAEmotionPathWorldUpWidgets[];    // hold info plus widgets
  42. global string $gAEmotionPathFollowCBG[];        // follow checkBoxGrp
  43.  
  44.  
  45. // The main template proc called when the first instance
  46. // of the motionPath attribute editor is opened.
  47. //
  48. global proc AEmotionPathTemplate( string $nodeName )
  49. {
  50.  
  51.     editorTemplate -beginScrollLayout;
  52.     
  53.         editorTemplate -beginLayout "Motion Path Attributes" -collapse 0;
  54.             editorTemplate -addControl "uValue";
  55.     
  56.             // The fraction mode attribute value is presented in the
  57.             // UI as "Parametric Length" which has the opposite
  58.             // boolean value.  Therefore, we need a custom control.
  59.             //
  60.             editorTemplate -callCustom 
  61.                 "AEmotionPathFractionModeNew"
  62.                 "AEmotionPathFractionModeReplace"
  63.                 "fractionMode";
  64.  
  65.             editorTemplate -callCustom
  66.                 "AEmotionPathFollowNew"
  67.                 "AEmotionPathFollowReplace"
  68.                 "follow";
  69.             
  70.             editorTemplate -addControl "worldUpType" 
  71.                     "AEmotionPathWorldUpControls";
  72.             editorTemplate -addControl "worldUpVector"; 
  73.             editorTemplate -callCustom
  74.                 "AEmotionPathWorldUpObjectNew"
  75.                 "AEmotionPathWorldUpObjectReplace"
  76.                 "worldUpMatrix";
  77.  
  78.             editorTemplate -addControl "inverseUp";
  79.             editorTemplate -addControl "inverseFront";
  80.             editorTemplate -addControl "frontAxis";
  81.             editorTemplate -addControl "upAxis";
  82.             editorTemplate -addControl "frontTwist";
  83.             editorTemplate -addControl "upTwist";
  84.             editorTemplate -addControl "sideTwist";
  85.             
  86.             editorTemplate -addSeparator;
  87.  
  88.             editorTemplate -addControl "bank" 
  89.                     "AEmotionPathBankControls";
  90.             editorTemplate -addControl "bankScale";
  91.             editorTemplate -addControl "bankLimit";
  92.         editorTemplate -endLayout;
  93.     // include/call base class/node attributes
  94.     AEdependNodeTemplate $nodeName;
  95.  
  96.     editorTemplate -addExtraControls;
  97.     editorTemplate -endScrollLayout;
  98.  
  99.     editorTemplate -suppress "fractionMode";
  100.     editorTemplate -suppress "follow";
  101.     editorTemplate -suppress "normal";
  102.     editorTemplate -suppress "worldUpType";
  103. //    editorTemplate -suppress "worldUpVector";
  104.     editorTemplate -suppress "worldUpMatrix";
  105.     editorTemplate -suppress "positionMarkerTime";
  106.     editorTemplate -suppress "orientationMarkerTime";
  107.     editorTemplate -suppress "rotateOrder";
  108.     editorTemplate -suppress "flowNode";
  109.     editorTemplate -suppress "oldFlowNode";
  110.     editorTemplate -suppress "geometryPath";
  111. }
  112.  
  113.  
  114. // This proc gets called by the scriptJob which is watching the
  115. // follow attribute
  116. //
  117. global proc AEmotionPathFollowScriptJobProc(string $plug, string $followControl)
  118. {
  119.     checkBoxGrp -e -v1 `getAttr $plug` $followControl;
  120.     AEmotionPathFollowControlUpdate($plug,$followControl,1);
  121. }
  122.  
  123.  
  124. // The creation proc for the custom follow checkBoxGrp.
  125. //
  126. global proc AEmotionPathFollowNew( string $plug )
  127. {
  128.     global string $gAEmotionPathFollowCBG[];
  129.  
  130.     // get the nodeName
  131.     //
  132.     string $buffer[];
  133.     tokenize($plug,".|",$buffer);
  134.     string $nodeName = $buffer[0];
  135.  
  136.     // data is stored in triples in $gAEmotionPathFollowCBG;
  137.     // the first item is the nodename, the second is the parent layout
  138.     // and the third is the control name
  139.     //
  140.     int $numMotionPathAEs = size($gAEmotionPathFollowCBG);
  141.     $gAEmotionPathFollowCBG[$numMotionPathAEs] = $nodeName;
  142.     $gAEmotionPathFollowCBG[$numMotionPathAEs+1] = `setParent -q`;
  143.  
  144.     // build the checkBoxGrp
  145.     //
  146.     setUITemplate -pst attributeEditorTemplate;
  147.     string $followControl = `checkBoxGrp
  148.         -ncb 1 -l "" -l1 "Follow"
  149.         AEmotionPathFollowCheckBoxGrp`;
  150.     string $cc = "AEmotionPathFollowControlUpdate "+$plug+" "+$followControl+" 0";
  151.     checkBoxGrp -e
  152.         -cc $cc
  153.         $followControl;
  154.  
  155.     // store the control name in the global string array
  156.     // so that we can keep track of it
  157.     //
  158.     $gAEmotionPathFollowCBG[$numMotionPathAEs+2] = $followControl;
  159.  
  160.     // set the original value
  161.     //
  162.     checkBoxGrp -e -v1 `getAttr $plug` $followControl;
  163.  
  164.     // build the callback mechanism
  165.     //
  166.     string $cmd = "AEmotionPathFollowScriptJobProc "+$plug+" "+$followControl;
  167.     scriptJob -rp -p $followControl -ac $plug $cmd;
  168. }
  169.  
  170.  
  171. // A local proc used to find a control given current UI parent layout
  172. //
  173. proc string getCurrentFollowControl( string $nodeName )
  174. {
  175.     global string $gAEmotionPathFollowCBG[];
  176.  
  177.     // look for the correct parent
  178.     //
  179.     string $curParent = `setParent -q`;
  180.     int $index = -1;
  181.     int $i;
  182.     for ($i = 0; $i < size($gAEmotionPathFollowCBG); $i += 3 ) {
  183.         if ( $curParent == $gAEmotionPathFollowCBG[$i+1] ) {
  184.             $index = $i+2;
  185.             break;
  186.         }
  187.     }
  188.     string $cbg = "AEmotionPathFollowCheckBoxGrp";
  189.     if ($index != -1) {
  190.         $cbg = $gAEmotionPathFollowCBG[$index];
  191.         $gAEmotionPathFollowCBG[$index-2] = $nodeName;
  192.     }
  193.     return $cbg;
  194. }
  195.  
  196.  
  197. // This proc is called when the user switches from one motionPath
  198. // to another so that we can reuse UI (which is faster than having
  199. // to delete and recreate it)
  200. //
  201. global proc AEmotionPathFollowReplace( string $plug )
  202. {
  203.     // get the nodeName
  204.     //
  205.     string $buffer[];
  206.     tokenize($plug,".|",$buffer);
  207.     string $nodeName = $buffer[0];
  208.  
  209.     // get the parent
  210.     //
  211.     string $followControl = getCurrentFollowControl( $nodeName );
  212.  
  213.     // update the checkBoxGrp
  214.     //
  215.     string $cc = "AEmotionPathFollowControlUpdate "+$plug+" "+$followControl+" 0";
  216.     checkBoxGrp -e
  217.         -v1 `getAttr $plug`
  218.         -cc $cc
  219.         $followControl;
  220.  
  221.     // update the callback mechanism
  222.     //
  223.     string $cmd = "AEmotionPathFollowScriptJobProc "+$plug+" "+$followControl;
  224.     scriptJob -rp -p $followControl -ac $plug $cmd;
  225. }
  226.  
  227.  
  228. // This proc gets called when the user hits the follow checkBoxGrp,
  229. // or when the follow attribute has changed (i.e. the user typed
  230. // `pathAnimation -e -follow [true|false] motionPath1`).
  231. // This proc will dim/undim all related controls appropriately.
  232. //
  233. global proc AEmotionPathFollowControlUpdate(string $plug,
  234.                                             string $followControl,
  235.                                             int $fromScriptJob)
  236. {
  237.     global string $gAEmotionPathNormalRBG[];
  238.  
  239.     // get the nodeName from the plug
  240.     //
  241.     string $buffer[];
  242.     tokenize($plug,".",$buffer);
  243.     string $nodeName = $buffer[0];
  244.  
  245.     // get the current value of the checkBoxGrp
  246.     //
  247.     int $value = `checkBoxGrp -q -v1 $followControl`;
  248.  
  249.     // a pathAnimation command should only be issued if the
  250.     // user hit the follow checkBoxGrp
  251.     //
  252.     if (!$fromScriptJob)
  253.         pathAnimation -edit -follow $value $nodeName;
  254.  
  255.     // dim/undim controls for related attributes appropriately
  256.     //
  257.     if ($value == 1) {
  258.         // Enable/disable the world up controls
  259.         editorTemplate -dimControl $nodeName "worldUpType" false;
  260.         AEmotionPathWorldUpControls( $nodeName );
  261.  
  262.         editorTemplate -dimControl $nodeName "inverseUp" false;
  263.         editorTemplate -dimControl $nodeName "inverseFront" false;
  264.         editorTemplate -dimControl $nodeName "frontAxis" false;
  265.         editorTemplate -dimControl $nodeName "upAxis" false;
  266.         editorTemplate -dimControl $nodeName "frontTwist" false;
  267.         editorTemplate -dimControl $nodeName "upTwist" false;
  268.         editorTemplate -dimControl $nodeName "sideTwist" false;
  269.         editorTemplate -dimControl $nodeName "bank" false;
  270.         AEmotionPathBankControls $nodeName;
  271.     } else {
  272.         // Disable the world up controls
  273.         editorTemplate -dimControl $nodeName "worldUpType" true;
  274.         AEmotionPathWorldUpControls( $nodeName );
  275.  
  276.         editorTemplate -dimControl $nodeName "inverseUp" true;
  277.         editorTemplate -dimControl $nodeName "inverseFront" true;
  278.         editorTemplate -dimControl $nodeName "frontAxis" true;
  279.         editorTemplate -dimControl $nodeName "upAxis" true;
  280.         editorTemplate -dimControl $nodeName "frontTwist" true;
  281.         editorTemplate -dimControl $nodeName "upTwist" true;
  282.         editorTemplate -dimControl $nodeName "sideTwist" true;
  283.         editorTemplate -dimControl $nodeName "bank" true;
  284.         editorTemplate -dimControl $nodeName "bankScale" true;
  285.         editorTemplate -dimControl $nodeName "bankLimit" true;
  286.     }
  287. }
  288.  
  289.  
  290. // This proc will dim/undim the bank controls as required
  291. //
  292. global proc AEmotionPathBankControls(string $nodeName)
  293. {
  294.     $nodeAttr = $nodeName +".bank";
  295.     $value = `getAttr $nodeAttr`;
  296.     if ($value == 1) {
  297.         editorTemplate -dimControl $nodeName "bankScale" false;
  298.         editorTemplate -dimControl $nodeName "bankLimit" false;
  299.     } else {
  300.         editorTemplate -dimControl $nodeName "bankScale" true;
  301.         editorTemplate -dimControl $nodeName "bankLimit" true;
  302.     }
  303. }
  304.  
  305. proc setStateOfWorldUpObjectControls( string $nodeName, int $state )
  306. {
  307.     global string $gAEmotionPathWorldUpWidgets[];
  308.  
  309.     // Update the world up object text field for all attribute
  310.     // editors looking at this node
  311.  
  312.     int $i;
  313.     for ($i = 0; $i < size($gAEmotionPathWorldUpWidgets); $i += 3 )
  314.     {
  315.         if ( $nodeName == $gAEmotionPathWorldUpWidgets[$i] ) 
  316.         {
  317.             string $worldUpObjectControl = $gAEmotionPathWorldUpWidgets[$i+2];
  318.             if ( `textFieldGrp -exists $worldUpObjectControl` )
  319.             {
  320.                 textFieldGrp -e -enable $state $worldUpObjectControl;
  321.             }
  322.         }
  323.     }
  324. }
  325.  
  326. // This proc will dim/undim the world up controls as required
  327. global proc AEmotionPathWorldUpControls(string $nodeName)
  328. {
  329.     if ( `getAttr ($nodeName+".follow")` )
  330.     {
  331.         $nodeAttr = $nodeName +".worldUpType";
  332.         int $value = `getAttr $nodeAttr`;
  333.         switch ($value) 
  334.         {
  335.         case 0: // Scene Up
  336.         case 4: // Normal
  337.             editorTemplate -dimControl $nodeName "worldUpVector" true;
  338.             setStateOfWorldUpObjectControls( $nodeName, false );
  339.             break;
  340.         case 1: // Object Up
  341.             editorTemplate -dimControl $nodeName "worldUpVector" true;
  342.             setStateOfWorldUpObjectControls( $nodeName, true );
  343.             break;
  344.         case 2: // Object Rotation Up
  345.             editorTemplate -dimControl $nodeName "worldUpVector" false;
  346.             setStateOfWorldUpObjectControls( $nodeName, true );
  347.             break;
  348.         case 3: // Vector
  349.             editorTemplate -dimControl $nodeName "worldUpVector" false;
  350.             setStateOfWorldUpObjectControls( $nodeName, false );
  351.             break;
  352.         default:
  353.             break;
  354.         }
  355.     }
  356.     else
  357.     {
  358.         editorTemplate -dimControl $nodeName "worldUpVector" true;
  359.         setStateOfWorldUpObjectControls( $nodeName, false );
  360.     }
  361. }
  362.  
  363.  
  364. // This proc gets called by the UI widget for the
  365. // worldUpMatrix attribute
  366. //
  367. global proc AEmotionPathWorldUpObjectControlProc(string $nodeName,
  368.                                                  string $widget)
  369. {
  370.     // Get the current value of the widget
  371.  
  372.     string $value = `textFieldGrp -q -text $widget`;
  373.  
  374.     // setAttr just isn't sufficient for worldUpMatrix
  375.  
  376.     pathAnimation -edit -worldUpObject $value $nodeName;
  377. }
  378.  
  379. // This proc gets called by the scriptJob which is watching the
  380. // worldUpMatrix attribute
  381. //
  382. global proc AEmotionPathWorldUpObjectScriptJobProc(string $nodeName,
  383.                                                    string $widget)
  384. {
  385.     textFieldGrp -e
  386.         -text `pathAnimation -q -worldUpObject $nodeName`
  387.         $widget;
  388. }
  389.  
  390. // Local proc shared by AEmotionPathWorldUpObjectNew() and AEmotionPathWorldUpObjectReplace()
  391. proc updateWorldUpObject( string $nodeName, string $plug, string $worldUpObjectControl )
  392. {
  393.     // Initialize/update the textFieldGrp
  394.  
  395.     string $cmd1 = "AEmotionPathWorldUpObjectControlProc "+$nodeName+" "+$worldUpObjectControl;
  396.     textFieldGrp -e
  397.         -text `pathAnimation -q -worldUpObject $nodeName`
  398.         -cc $cmd1
  399.         $worldUpObjectControl;
  400.     
  401.     // Setup/update the scriptJob callback mechanism
  402.  
  403.     string $cmd2 = "AEmotionPathWorldUpObjectScriptJobProc "+$nodeName+" "+$worldUpObjectControl;
  404.     scriptJob -rp -p $worldUpObjectControl -ac $plug $cmd2;
  405. }
  406.  
  407. // The custom creation proc for the worldUpMatrix attribute
  408. //
  409. global proc AEmotionPathWorldUpObjectNew( string $plug )
  410. {
  411.     global string $gAEmotionPathWorldUpWidgets[];
  412.  
  413.     // Get the node name
  414.  
  415.     string $buffer[];
  416.     tokenize($plug,".|",$buffer);
  417.     string $nodeName = $buffer[0];
  418.  
  419.     // Save the node name and the parent info in the global
  420.     // string array
  421.  
  422.     int $numMotionPathAEs = size($gAEmotionPathWorldUpWidgets);
  423.     $gAEmotionPathWorldUpWidgets[$numMotionPathAEs] = $nodeName;
  424.     $gAEmotionPathWorldUpWidgets[$numMotionPathAEs+1] = `setParent -q`;
  425.  
  426.     // Create the textFieldGrp
  427.  
  428.     setUITemplate -pst attributeEditorTemplate;
  429.  
  430.     string $worldUpObjectControl =
  431.         `textFieldGrp -l "World Up Object" AEmotionPathWorldUpObjectField`;
  432.  
  433.     // Save the control for possible later reuse
  434.     $gAEmotionPathWorldUpWidgets[$numMotionPathAEs+2] = $worldUpObjectControl;
  435.  
  436.     setUITemplate -ppt;
  437.  
  438.     updateWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  439. }
  440.  
  441. global proc AEmotionPathWorldUpObjectReplace( string $plug )
  442. {
  443.     global string $gAEmotionPathWorldUpWidgets[];
  444.  
  445.     // Get the node name
  446.  
  447.     string $buffer[];
  448.     tokenize($plug,".|",$buffer);
  449.     string $nodeName = $buffer[0];
  450.  
  451.     // Reuse the existing control
  452.  
  453.     string $curParent = `setParent -q`;
  454.     int $index = -1;
  455.     int $i;
  456.     for ( $i = 0; $i < size($gAEmotionPathWorldUpWidgets); $i += 3 ) 
  457.     {
  458.         if ( $curParent == $gAEmotionPathWorldUpWidgets[$i+1] )
  459.         {
  460.             $index = $i;
  461.             break;
  462.         }
  463.     }
  464.     string $worldUpObjectControl = "AEmotionPathWorldUpObjectField";
  465.     if ($index != -1)
  466.     {
  467.         $gAEmotionPathWorldUpWidgets[$index] = $nodeName;
  468.         $worldUpObjectControl = $gAEmotionPathWorldUpWidgets[$index+2];
  469.     }
  470.  
  471.     updateWorldUpObject( $nodeName, $plug, $worldUpObjectControl );
  472. }
  473.  
  474. global proc AEmotionPathFractionModeNew( string $attrName )
  475. //
  476. // Description:
  477. //    Create a new checkBoxGrp for the attribute.
  478. //    
  479. {
  480.     checkBoxGrp -ncb 1 -l "" -label1 "Parametric Length" 
  481.         AEmotionPathFractionModeCheckBox;
  482.         
  483.     AEmotionPathFractionModeReplace( $attrName );
  484. }
  485.  
  486. global proc AEmotionPathFractionModeReplace( string $attrName )
  487. //
  488. // Description:
  489. //    Reconnect this control to the new attribute.
  490. //    
  491. {
  492.     // The value of the check box is the opposite of the
  493.     // boolean-valued attribute.
  494.     //
  495.     int  $attrValue = (! `getAttr $attrName`);
  496.  
  497.     checkBoxGrp -e 
  498.         -value1 $attrValue
  499.         -changeCommand ( "setAttr \"" + $attrName + "\" (!#1)" ) 
  500.         AEmotionPathFractionModeCheckBox;
  501.  
  502.     scriptJob -replacePrevious -p AEmotionPathFractionModeCheckBox 
  503.         -attributeChange $attrName 
  504.         ( "AEmotionPathFractionModeChanged " + $attrName + 
  505.           " AEmotionPathFractionModeCheckBox" );
  506. }
  507.  
  508. global proc AEmotionPathFractionModeChanged( string $attrName,
  509.                                              string $checkBoxGrp )
  510. //
  511. // Description:
  512. //    
  513. //    
  514. {
  515.     int $attrValue = (! `getAttr $attrName`);
  516.     checkBoxGrp -e -v1 $attrValue AEmotionPathFractionModeCheckBox;
  517. }
  518.